<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>Centos7安装单节点kubernetes | shouzimu</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="官方教程链接：https:&#x2F;&#x2F;kubernetes.io&#x2F;zh&#x2F;docs&#x2F;tasks&#x2F;tools&#x2F;install-kubectl&#x2F; 安装 kubectl1、配置使用阿里云的源 123456789cat &lt;&lt;EOF &gt; &#x2F;etc&#x2F;yum.repos.d&#x2F;kubernetes.repo[kubernetes]name&#x3D;Kubernetesbaseurl&#x3D;https:&#x2F;&#x2F;mirrors">
<meta property="og:type" content="article">
<meta property="og:title" content="Centos7安装单节点kubernetes">
<meta property="og:url" content="https://shouzimu.gitee.io/2020/11/12/k8s-single/index.html">
<meta property="og:site_name" content="shouzimu">
<meta property="og:description" content="官方教程链接：https:&#x2F;&#x2F;kubernetes.io&#x2F;zh&#x2F;docs&#x2F;tasks&#x2F;tools&#x2F;install-kubectl&#x2F; 安装 kubectl1、配置使用阿里云的源 123456789cat &lt;&lt;EOF &gt; &#x2F;etc&#x2F;yum.repos.d&#x2F;kubernetes.repo[kubernetes]name&#x3D;Kubernetesbaseurl&#x3D;https:&#x2F;&#x2F;mirrors">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-11-12T12:00:26.000Z">
<meta property="article:modified_time" content="2020-11-12T12:13:06.108Z">
<meta property="article:author" content="shouzimu">
<meta property="article:tag" content="cloud">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="shouzimu" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/css/style.css">

<meta name="generator" content="Hexo 5.2.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">shouzimu</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="https://shouzimu.gitee.io"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-k8s-single" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2020/11/12/k8s-single/" class="article-date">
  <time datetime="2020-11-12T12:00:26.000Z" itemprop="datePublished">2020-11-12</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Centos7安装单节点kubernetes
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>官方教程链接：<a target="_blank" rel="noopener" href="https://kubernetes.io/zh/docs/tasks/tools/install-kubectl/">https://kubernetes.io/zh/docs/tasks/tools/install-kubectl/</a></p>
<h2 id="安装-kubectl"><a href="#安装-kubectl" class="headerlink" title="安装 kubectl"></a>安装 kubectl</h2><p>1、配置使用阿里云的源</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">cat &lt;&lt;EOF &gt; /etc/yum.repos.d/kubernetes.repo</span><br><span class="line">[kubernetes]</span><br><span class="line">name=Kubernetes</span><br><span class="line">baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64</span><br><span class="line">enabled=1</span><br><span class="line">gpgcheck=1</span><br><span class="line">repo_gpgcheck=1</span><br><span class="line">gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg</span><br><span class="line">EOF</span><br></pre></td></tr></table></figure>



<p>2、安装kubectl</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install -y kubectl</span><br></pre></td></tr></table></figure>



<h3 id="安装-Minikube"><a href="#安装-Minikube" class="headerlink" title="安装 Minikube"></a>安装 Minikube</h3><p>1、下载minikube</p>
<p>可以下载并使用一个单节点二进制文件。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \</span><br><span class="line">  &amp;&amp; chmod +x minikube</span><br></pre></td></tr></table></figure>

<p>不过由于googleapis不能访问，我们使用如下命令从github上下载，具体版本号可以到github上查看</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -Lo minikube https:&#x2F;&#x2F;github.com&#x2F;kubernetes&#x2F;minikube&#x2F;releases&#x2F;download&#x2F;v1.10.0-beta.1&#x2F;minikube-linux-amd64   &amp;&amp; chmod +x minikube</span><br></pre></td></tr></table></figure>



<p>2、将 Minikube 可执行文件添加至 path</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo mkdir -p /usr/local/bin/</span><br><span class="line">sudo install minikube /usr/local/bin/</span><br></pre></td></tr></table></figure>



<p>3、启动</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@iZm5e7y9qoyl006b96mwaaZ k8s]#  minikube start --driver=none</span><br><span class="line">* minikube v1.10.0-beta.1 on Centos 7.7.1908</span><br><span class="line">* Using the none driver based on user configuration</span><br><span class="line">X Sorry, Kubernetes v1.18.0 requires conntrack to be installed in root&#x27;s path</span><br></pre></td></tr></table></figure>

<p>发现报了一个错误</p>
<p>安装conntrack</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install -y conntrack-tools</span><br></pre></td></tr></table></figure>

<p>再次执行进入漫长的下载</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">[root@iZm5e7y9qoyl006b96mwaaZ k8s]#  minikube start --driver&#x3D;none</span><br><span class="line">* minikube v1.10.0-beta.1 on Centos 7.7.1908</span><br><span class="line">* Using the none driver based on user configuration</span><br><span class="line">* Starting control plane node minikube in cluster minikube</span><br><span class="line">* Running on localhost (CPUs&#x3D;2, Memory&#x3D;3789MB, Disk&#x3D;40183MB) ...</span><br><span class="line">* OS release is CentOS Linux 7 (Core)</span><br><span class="line">* Preparing Kubernetes v1.18.0 on Docker 1.13.1 ...</span><br><span class="line">    &gt; kubectl.sha256: 65 B &#x2F; 65 B [--------------------------] 100.00% ? p&#x2F;s 0s</span><br><span class="line">    &gt; kubelet.sha256: 65 B &#x2F; 65 B [--------------------------] 100.00% ? p&#x2F;s 0s</span><br><span class="line">! This bare metal machine is having trouble accessing https:&#x2F;&#x2F;k8s.gcr.io</span><br><span class="line">* To pull new external images, you may need to configure a proxy: https:&#x2F;&#x2F;minikube.sigs.k8s.io&#x2F;docs&#x2F;reference&#x2F;networking&#x2F;proxy&#x2F;</span><br><span class="line">    &gt; kubeadm.sha256: 65 B &#x2F; 65 B [--------------------------] 100.00% ? p&#x2F;s 0s</span><br><span class="line">    &gt; kubectl: 41.98 MiB &#x2F; 41.98 MiB [---------------] 100.00% 11.29 MiB p&#x2F;s 4s</span><br><span class="line">    &gt; kubeadm: 37.96 MiB &#x2F; 37.96 MiB [----------------] 100.00% 7.99 MiB p&#x2F;s 5s</span><br><span class="line">    &gt; kubelet: 2.35 MiB &#x2F; 108.01 MiB [&gt;_______] 2.17% 11.00 KiB p&#x2F;s ETA 2h44m0s</span><br></pre></td></tr></table></figure>

<p>可以在启动命令上追加</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">--registry-mirror=https://替换为阿里云加速.mirror.aliyuncs.com</span><br><span class="line">minikube start --driver=none --image-repository=&#x27;registry.aliyuncs.com/google_containers&#x27;</span><br></pre></td></tr></table></figure>

<p>经过漫长等待出现下面输出</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">! kubectl and minikube configuration will be stored in /root</span><br><span class="line">! To use kubectl or minikube commands as your own user, you may need to relocate them. For example, to overwrite your own settings, run:</span><br><span class="line">* </span><br><span class="line">  - sudo mv /root/.kube /root/.minikube $HOME</span><br><span class="line">  - sudo chown -R $USER $HOME/.kube $HOME/.minikube</span><br><span class="line">* </span><br><span class="line">* This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true</span><br><span class="line">* Enabled addons: default-storageclass, storage-provisioner</span><br><span class="line">* Done! kubectl is now configured to use &quot;minikube&quot;</span><br></pre></td></tr></table></figure>

<p>说明启动成功</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">[root@iZm5e7y9qoyl006b96mwaaZ k8s]# minikube status</span><br><span class="line">minikube</span><br><span class="line">type: Control Plane</span><br><span class="line">host: Running</span><br><span class="line">kubelet: Running</span><br><span class="line">apiserver: Running</span><br><span class="line">kubeconfig: Configured</span><br><span class="line"></span><br><span class="line">[root@iZm5e7y9qoyl006b96mwaaZ k8s]# kubectl get nodes</span><br><span class="line">NAME                      STATUS   ROLES    AGE     VERSION</span><br><span class="line">izm5e7y9qoyl006b96mwaaz   Ready    master   3m22s   v1.18.0</span><br><span class="line"></span><br><span class="line">[root@iZm5e7y9qoyl006b96mwaaZ k8s]# kubectl  cluster-info</span><br><span class="line">Kubernetes master is running at https://172.31.202.153:8443</span><br><span class="line">KubeDNS is running at https://172.31.202.153:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy</span><br><span class="line"></span><br><span class="line">To further debug and diagnose cluster problems, use &#x27;kubectl cluster-info dump&#x27;.</span><br></pre></td></tr></table></figure>





<h3 id="测试"><a href="#测试" class="headerlink" title="测试"></a>测试</h3><p>官网链接：<a target="_blank" rel="noopener" href="https://kubernetes.io/docs/setup/learning-environment/minikube/">https://kubernetes.io/docs/setup/learning-environment/minikube/</a></p>
<p>1、使用名为 <code>echoserver</code> 的镜像创建一个 Kubernetes Deployment，并使用 <code>--port</code> 在端口 8080 上暴露服务。<code>echoserver</code> 是一个简单的 HTTP 服务器。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">kubectl run hello-minikube --image=registry.aliyuncs.com/google_containers/echoserver:1.10 --port=8080</span><br><span class="line"></span><br><span class="line">上面这个网站描述输出的是pod，跟预期的deployment不符</span><br><span class="line">pod/hello-minikube created</span><br><span class="line"></span><br><span class="line">换成下面的命令试一下</span><br><span class="line">kubectl create deployment hello-minikube --image=registry.aliyuncs.com/google_containers/echoserver:1.10</span><br><span class="line">输出</span><br><span class="line">deployment.apps/hello-minikube created</span><br></pre></td></tr></table></figure>



<p>2、查看pod状态</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@iZm5e7y9qoyl006b96mwaaZ k8s]# kubectl get pod</span><br><span class="line">NAME             READY   STATUS    RESTARTS   AGE</span><br><span class="line">hello-minikube   1/1     Running   0          6m18s</span><br></pre></td></tr></table></figure>



<p>3、将<code>hello-minikube</code> Deployment，需要将其作为 Service 公开</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">kubectl expose deployment hello-minikube --type&#x3D;NodePort --port&#x3D;8080</span><br><span class="line"></span><br><span class="line">service&#x2F;hello-minikube exposed</span><br></pre></td></tr></table></figure>



<p>4、获取暴露 Service 的 URL 以查看 Service 的详细信息：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">minikube service hello-minikube --url</span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="article-footer">
      <a data-url="https://shouzimu.gitee.io/2020/11/12/k8s-single/" data-id="ckhes672e0004zoizfnthcadj" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/cloud/" rel="tag">cloud</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2020/11/12/remote-debug/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          idea远程调试
        
      </div>
    </a>
  
  
    <a href="/2020/11/12/cdh-esgyn-change-ip/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">CDH+esgynDB 修改ip</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/cloud/" rel="tag">cloud</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/elasticsearch/" rel="tag">elasticsearch</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/esgynDB/" rel="tag">esgynDB</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/" rel="tag">java</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/os/" rel="tag">os</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/cloud/" style="font-size: 10px;">cloud</a> <a href="/tags/elasticsearch/" style="font-size: 10px;">elasticsearch</a> <a href="/tags/esgynDB/" style="font-size: 10px;">esgynDB</a> <a href="/tags/java/" style="font-size: 10px;">java</a> <a href="/tags/os/" style="font-size: 10px;">os</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/11/">十一月 2020</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2020/11/12/essync/">es+canal+logstash优化用户查询</a>
          </li>
        
          <li>
            <a href="/2020/11/12/centos-static-ip/">centos配置静态ip</a>
          </li>
        
          <li>
            <a href="/2020/11/12/remote-debug/">idea远程调试</a>
          </li>
        
          <li>
            <a href="/2020/11/12/k8s-single/">Centos7安装单节点kubernetes</a>
          </li>
        
          <li>
            <a href="/2020/11/12/cdh-esgyn-change-ip/">CDH+esgynDB 修改ip</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2020 shouzimu<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">

  
<script src="/fancybox/jquery.fancybox.pack.js"></script>




<script src="/js/script.js"></script>




  </div>
</body>
</html>